package org.yjc.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yjc.entity.Teacher;
import org.yjc.repository.TeacherRepository;

@Service
public class TeacherService {
	@Autowired
	private TeacherRepository teacherDAO;
	
	/**
	 * 教师登陆功能
	 * @param userName 用户名
	 * @param passWord 密码
	 * @return
	 */
	public Teacher login(String userName, String passWord) {
		return teacherDAO.findByUserNameAndPassWord(userName,passWord);
	}
	
	/**
	 * 
	 * @return 查询所有教师
	 */
	public List<Teacher> findAll() {
		return teacherDAO.findAll();
	}

	public Teacher findById(Integer id) {
		Optional<Teacher> optional = teacherDAO.findById(id);
		if(optional.isPresent()) {
			return optional.get();
		}
		return null;
	}

	public void save(Teacher teacher2) {
		teacherDAO.save(teacher2);
		
	}
}
